<?php
/**
 * Created by PhpStorm.
 * User: 17732
 * Date: 2018/6/20
 * Time: 14:04
 */

namespace app\admin\model;


use think\Db;
use think\Model;

class User extends Model
{
    /**
     *  用户添加
     */
    public static function addUser($userArr = array()){
        if(empty($userArr) || !is_array($userArr)) return;
        $adduser = Db::name('user')->insert($userArr);
        return $adduser;
    }
    /**
     *  用户查询
     */
    public static function selectUser($account){
        $query = Db::name('user')->where('account',$account)->where('ustates','1')->find();
        return $query;
    }
    /**
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function selectAllUser(){
        $query = Db::name('user')->select();  //->where('ustates','1')
        return $query;
    }
    /**
     * 更新某个字段的值
     * @param $id  id
     * @param $k   字段
     * @param $v   字段值
     * @return int
     */
    public static function updateUserOne($id,$k,$v){
        return Db::table('user')->where('id',$id)->update([$k=>$v]);
    }

    public static function searchUser($name){
        $query = Db::name('user')
            ->where('name','like','%'.$name.'%')
            ->select();
        return $query;
    }


}